package com.hulk.sequence;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author hulk
 * @date 2019-05-26
 * <p>
 * 发号器通用属性
 */
@Data
@Component
@ConfigurationProperties(prefix = SequenceProperties.PREFIX)
public class SequenceProperties {

	protected static final String PREFIX="spring.sequence";

	/**
	 * 获取range步长[可选，默认：3]
	 */
	private int step = 3;

	/**
	 * 序列号分配起始值[可选：默认：1]
	 */
	private long stepStart = 1;

	/**
	 * 业务名称
	 */
	private String bizName = "seq";

	private SequenceDbProperties db;

	private SequenceRedisProperties redis;

	private SequenceSnowflakeProperties snowflake;


	@Data
	public static class SequenceDbProperties {
		/**
		 * 表名称
		 */
		private String tableName = "xsequence";
		/**
		 * 重试次数
		 */
		private int retryTimes = 1;

	}

	@Data
	public static class SequenceRedisProperties{

		private String address;
		private String password;
		private int database = 0;
		private ClusterServer clusterServer;

		public ClusterServer getClusterServer() {
			return clusterServer;
		}

		public void setClusterServer(ClusterServer clusterServer) {
			this.clusterServer = clusterServer;
		}

		public static class ClusterServer{

			private List<String> nodeAddresses;

			public List<String> getNodeAddresses() {
				return nodeAddresses;
			}

			public void setNodeAddresses(List<String> nodeAddresses) {
				this.nodeAddresses = nodeAddresses;
			}
		}
	}

	@Data
	public static class SequenceSnowflakeProperties{

		/**
		 * 数据中心ID，值的范围在[0,31]之间，一般可以设置机房的IDC[必选]
		 */
		private long datacenterId;
		/**
		 * 工作机器ID，值的范围在[0,31]之间，一般可以设置机器编号[必选]
		 */
		private long workerId;
	}
}
